package gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import java.awt.Component;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.LayoutStyle.ComponentPlacement;

import entidades.Cliente;
import entidades.Funcionario;
import fachada.Fachada;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;

public class TelaCadastroFuncionario {

	/**
	 * chamando a instancia da fachada
	 */
	private Fachada fac = Fachada.obterInstancia();
	private JFrame frmFuncionario;
	private JTextField textNome;
	private JTextField textSobreNome;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaCadastroFuncionario window = new TelaCadastroFuncionario();
					window.frmFuncionario.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public TelaCadastroFuncionario() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmFuncionario = new JFrame();
		frmFuncionario.setTitle("Funcionario");
		frmFuncionario.getContentPane().setBackground(Color.DARK_GRAY);
		frmFuncionario.setBounds(100, 100, 450, 300);
		frmFuncionario.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JButton button = new JButton("Sair");
		button.setBackground(Color.LIGHT_GRAY);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frmFuncionario.dispose();
			}
		});

		JButton button_1 = new JButton("Remover");
		button_1.setBackground(Color.LIGHT_GRAY);

		JButton button_2 = new JButton("Pesquisar");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Funcionario f = fac.pesquisarFuncionario(textNome.getText());
				textNome.setText(f.getNome());
				textSobreNome.setText(f.getSobreNome());
			}
		});
		button_2.setBackground(Color.LIGHT_GRAY);

		JButton button_3 = new JButton("Atualizar");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fac.atualizar(textNome.getText(), textSobreNome.getText());
			}
		});
		button_3.setBackground(Color.LIGHT_GRAY);

		JButton button_4 = new JButton("Cadastro");
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Funcionario fun = new Funcionario(textNome.getText(),
						textSobreNome.getText());
				fac.inserirFuncionario(fun);

			}
		});
		button_4.setBackground(Color.LIGHT_GRAY);

		JLabel label_1 = new JLabel("Nome");
		label_1.setForeground(Color.LIGHT_GRAY);
		label_1.setFont(new Font("Tahoma", Font.PLAIN, 14));

		textNome = new JTextField();
		textNome.setForeground(Color.LIGHT_GRAY);
		textNome.setBackground(Color.DARK_GRAY);
		textNome.setText("");
		textNome.setColumns(10);

		textSobreNome = new JTextField();
		textSobreNome.setForeground(Color.LIGHT_GRAY);
		textSobreNome.setBackground(Color.DARK_GRAY);
		textSobreNome.setText("");
		textSobreNome.setColumns(10);

		JLabel label_2 = new JLabel("Sobre Nome");
		label_2.setForeground(Color.LIGHT_GRAY);
		label_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
		GroupLayout groupLayout = new GroupLayout(
				frmFuncionario.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(23)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
							.addGap(4)
							.addComponent(textNome, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
							.addGap(4)
							.addComponent(textSobreNome, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(button_4)
						.addComponent(button_3)
						.addComponent(button_2)
						.addComponent(button_1)
						.addComponent(button))
					.addGap(22))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(23)
					.addComponent(button_4)
					.addGap(24)
					.addComponent(button_3)
					.addGap(24)
					.addComponent(button_2)
					.addGap(24)
					.addComponent(button_1)
					.addGap(24)
					.addComponent(button))
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(77)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(textNome, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(11)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(textSobreNome, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
		);
		groupLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {button, button_1, button_2, button_3, button_4});
		frmFuncionario.getContentPane().setLayout(groupLayout);
	}

	// GET E SET
	public JFrame getTelaFuncionario() {
		return frmFuncionario;
	}

	public void setTelaFuncionario(JFrame frame) {
		this.frmFuncionario = frame;
	}
}
